package agenda;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import org.apache.commons.lang3.time.DateUtils;


public class Agenda implements Serializable{
	private List<Evenement> evenements;
	private String login;
	
	public Agenda(String login){
		evenements = new ArrayList<>();
		this.login = login;
	}
	
//	public void addContenu(Contenu contenu){
//		try {
//			news.publierContenu(contenu);
//		} catch (RemoteException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
	
	public Agenda() {
		// TODO Auto-generated constructor stub
	}

	public void addEvenement(Evenement evenement){
		evenements.add(evenement);
	}
	public void supEvenement(Evenement evenement){
		for (int i = 0; i < evenements.size(); i++) {
			 if(evenements.get(i).equals(evenement)){
				 evenements.remove(i);
				 break;
			 }
		}
	}
	
	@Override
	public String toString() {
		return login + "Evenements : \n" + evenements.toString() ;
	}
	


	public List<Evenement> getEvenements() {
		return evenements;
	}
	public Evenement getEvenement(Evenement even){
		for (int i = 0; i < evenements.size(); i++) {
			 if(evenements.get(i).equals(even)){
				 return evenements.get(i);
			 }
		}
		return null;
	}
	public List<Evenement> getEvenements(GregorianCalendar date){
		List<Evenement> l = getEvenements();
		System.out.println(l.size());
		List<Evenement> lres = new ArrayList(); 
		for (int i = 0; i < l.size(); i++) {
			System.out.println("test "+l.get(i).getDateDebut().compareTo(date));
			if(l.get(i).getDateDebut().compareTo(date)==0)
				lres.add(l.get(i));
		}
		System.out.println(lres);
		return lres;
	}
	
	public Evenement getEvenements(int year, int month, int day, int hour, int minute){
		GregorianCalendar d=new GregorianCalendar(year, month, day,hour,minute);
		Evenement res = null; 
		for (int i = 0; i < evenements.size(); i++) {
			if(DateUtils.truncatedEquals(evenements.get(i).getDateDebut(),d,Calendar.MINUTE))
				res = evenements.get(i);
		}
		System.out.println(year + " " + month + " " + day + " " + hour + " " + minute);
		System.out.println(res);
		return res;
	}

	public void setEvenements(List<Evenement> evenements) {
		this.evenements = evenements;
	}

	public String getUtilisateur() {
		return login;
	}
	public void setUtilisateur(String login) {
		this.login = login;
	}

}
